﻿var name = "#sidebar";

var sidebar_top_limit = 10;

var sidebar_top_margin = 20;

var sidebar_slide_duration = 500;
$(window).scroll(function () {

    offset = $(document).scrollTop() + sidebar_top_margin;



    if (offset < sidebar_top_limit)

        offset = sidebar_top_limit;



    $(name).animate({ top: offset }, { duration: sidebar_slide_duration, queue: false });

});